/**
 *1.首先需要进入menuconfig把分区表选择使用本地
 my_project
    build
    main
        mian.c
        CMakeLists.txt <--
    CMakeLists.txt
    partitions.csv  <--
    spiffs <-- 这个文件夹需要创建，用于把文件烧录到flash
分区表内容如下
# ESP-IDF Partition Table
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,           ,  0x1000,
factory,  app,  factory,       ,  2000K,
storage,  data, spiffs,        ,  2000K,
然后在mian文件夹里面的cmakelist.txt里面最后添加这个
spiffs_create_partition_image(storage ../spiffs FLASH_IN_PROJECT)

2.进入menuconfig，找到lvgl的File system on top of stdio API，勾选后配置如下
Use for lvgl need to turn on File system on top of stdio API
Set an upper cased letter on which the drive will accessible (e.g. 'A' i.e. 65 )
47
Set the working directory
/
>0 to cache this number of bytes in lv_fs_read()
1024

最后编译运行即可
*/

#include <stdio.h>
#include <dirent.h>
#include <string.h>

#include "esp_spiffs.h"
#include "esp_check.h"

static const char *TAG = "Spiffs";

esp_err_t spiffs_mount(void)
{
    esp_vfs_spiffs_conf_t conf = {
        .base_path = "/spiffs",
        .partition_label = "storage",
        .max_files = 5,
        .format_if_mount_failed = false,
    };

    esp_err_t ret_val = esp_vfs_spiffs_register(&conf);

    ESP_ERROR_CHECK(ret_val);

    size_t total = 0, used = 0;
    ret_val = esp_spiffs_info(conf.partition_label, &total, &used);
    if (ret_val != ESP_OK) {
        ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret_val));
    } else {
        ESP_LOGI(TAG, "Partition size: total: %dkb, used: %dkb", total/1000, used/1000);
    }

    DIR *dir;
    struct dirent *entry;

    dir = opendir("/spiffs");
    if (dir != NULL)
    {
        while ((entry = readdir(dir)) != NULL)
        {
            if (entry -> d_type != DT_DIR)
            {
                ESP_LOGI(TAG, "/spiffs/%s", entry -> d_name);
            }
        }
        
    };
    return ret_val;
}

esp_err_t spiffs_unmount(void)
{
    return esp_vfs_spiffs_unregister("storage");
}